package com.lenovo.smarttraffic.database.dao;

import android.content.Context;

/**
 * author  张猛
 **/
public class DaoManager_Peccancy {
    private Context mContext;
    private static final String DB_NAME = "need_title.db";
    private volatile static DaoManager_Peccancy mInstance_Peccancy;
    private static DaoMaster mDaoMaster_Peccancy;
    private static DaoMaster.DevOpenHelper mHelper_Peccancy;
    private static DaoSession mDaoSession_Peccancy;

    public DaoManager_Peccancy() {
    }

    public static DaoManager_Peccancy getmInstance_Peccancy() {
        if (mInstance_Peccancy == null) {
            synchronized (DaoManager_Need.class) {
                if (mInstance_Peccancy == null) {
                    mInstance_Peccancy = new DaoManager_Peccancy();
                }
            }
        }
        return mInstance_Peccancy;
    }

    public void init(Context context) {
        this.mContext = context;
    }


    public DaoMaster getDaoManager_Peccancy() {
        if (mDaoMaster_Peccancy == null) {
            mHelper_Peccancy = new DaoMaster.DevOpenHelper(mContext, DB_NAME, null);
            mDaoMaster_Peccancy = new DaoMaster(mHelper_Peccancy.getWritableDatabase());
        }
        return mDaoMaster_Peccancy;
    }

    public DaoSession getDaoSession_Peccancy() {
        if (mDaoSession_Peccancy == null) {
            if (mDaoMaster_Peccancy == null) {
                mDaoMaster_Peccancy = getDaoManager_Peccancy();
            }
            mDaoSession_Peccancy = mDaoMaster_Peccancy.newSession();
        }
        return mDaoSession_Peccancy;
    }

    public void closeConnection() {
        closeHelper();
        closeDaoSession();
    }

    public void closeHelper() {
        if (mHelper_Peccancy != null) {
            mHelper_Peccancy.close();
            mHelper_Peccancy = null;
        }
    }

    public void closeDaoSession() {
        if (mDaoSession_Peccancy != null) {
            mDaoSession_Peccancy.clear();
            mDaoSession_Peccancy = null;
        }
    }

}
